package Comparable;

public class Test1 {
    public static void main(String[] args) {
        Studdent s1 = new Studdent("a", 12);
        Studdent s2 = new Studdent("b", 13);

        Comparable max = getMax(s1, s2);
        System.out.println(max);
    }

    public static Comparable getMax(Comparable c1, Comparable c2) {
        int result = c1.compareTo(c2);
        if (result >= 0) {
            return c1;
        } else {
            return c2;
        }
    }

}

class Studdent implements Comparable<Studdent> {
    private String name;
    private int age;

    public Studdent() {
    }

    public Studdent(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Studdent{name = " + name + ", age = " + age + "}";
    }


    @Override
    public int compareTo(Studdent o) {
        return this.getAge() - o.getAge();
    }
}
